package com.zc.im.seqsvr.converter;

import com.zc.im.common.constant.enums.BaseEnum;
import com.zc.im.common.util.EnumUtil;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;

/**
 * Project：im
 * Date：2022/4/21
 * Time：9:55
 * Description：数字转枚举
 *
 * @author Challen.Zhang
 * @version 1.0
 */
public class IntegerToBaseEnumConverter<T extends BaseEnum<Integer>> implements Converter<Integer, T> {

    private final Class<T> enumType;

    public IntegerToBaseEnumConverter(Class<T> enumType) {
        this.enumType = enumType;
    }

    @Override
    public T convert(Integer source) {
        return EnumUtil.getEnum(source, enumType);
    }
}
